function [R1,R2,R]=tsk_type2(X,M,sigma,C,S);
R1=[];
R2=[];
[L,n]=size(X);
[m,n]=size(M);

for i=1:L
U=[];
for j=1:m
u=1;
for t=1:n
u=u*gaussmf(X(i,t),[sigma(j,t),M(j,t)]);
end
U=[U,u];
end

c2=C(:,1)+S(:,1);
c1=C(:,1)-S(:,1);
for t=1:n
c2=c2+C(:,t+1)*X(i,t)+S(:,t+1)*abs(X(i,t));
c1=c1+C(:,t+1)*X(i,t)-S(:,t+1)*abs(X(i,t));
end

c0=(c1+c2)/2;
s=c2-c0;

h=U;
delta=U-h;
[l_out,r_out] = interval_wtdavg(c0',s',h,delta);
R1=[R1,l_out];
R2=[R2,r_out];
end

R=(R1+R2)/2;
